package com.kongyz.registry;

import org.apache.zookeeper.KeeperException;

import java.io.IOException;
import java.util.List;

/**
 * @author kongyz
 * @date 2018/7/18 22:29
 * @Description:
 */
public class ListGroup extends CreateGroup {

    public void list(String groupName){
        String path="/"+groupName;
        try {
            List<String> children=zk.getChildren(path,false);

            if(children.isEmpty()){
                System.out.println("该子节点不存在子节点："+groupName);
                System.exit(1);
            }
            for (String child:children){
                System.out.println(child);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (KeeperException.NoNodeException e) {
            System.out.println("不存在的子节点");
            System.exit(1);
            e.printStackTrace();
        } catch (KeeperException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        ListGroup listGroup=new ListGroup();
        try {
            listGroup.connect("192.168.88.66");
            Thread.sleep(100);
            listGroup.list("kongyz");
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }

}
